 //543.二叉树的直径
 //https://leetcode.cn/problems/diameter-of-binary-tree/?envType=study-plan-v2&envId=top-100-liked
class Solution {
    int ret = 0;

    int depth(TreeNode* root)
    {
        if(!root) return 0;
        int l = depth(root->left);
        int r = depth(root->right);
        ret = max(l+r+1,ret);
        return 1+max(l,r);
    }
public:
    //最远两节点的路径 最长->最短
    int diameterOfBinaryTree(TreeNode* root) {
        depth(root);
        return ret-1;
    }
};